import VueRouter from "vue-router";
import Home from "@/pages/Home.vue";
import AdminEdit from "@/pages/admin/AdminEdit.vue";
import AdminList from "@/pages/admin/AdminList.vue";
import AdminSave from "@/pages/admin/AdminSave.vue";
import UserList from "@/pages/user/UserList.vue";
import UserEdit from "@/pages/user/UserEdit.vue";
import WarehouseList from "@/pages/ware/WarehouseList.vue";
import WarehouseEdit from "@/pages/ware/WarehouseEdit.vue";
import GoodCateList from "@/pages/goods_cate/GoodCateList.vue";
import GoodCateEdit from "@/pages/goods_cate/GoodCateEdit.vue";
import GoodsList from "@/pages/goods/GoodsList.vue";
import GoodsEdit from "@/pages/goods/GoodsEdit.vue";
import UserSave from "@/pages/user/UserSave.vue";
import GoodCateSave from "@/pages/goods_cate/GoodCateSave.vue";
import WarehouseSave from "@/pages/ware/WarehouseSave.vue";
import GoodsSave from "@/pages/goods/GoodsSave.vue";
import OptRecordList from "@/pages/opt_record/OptRecordList.vue";
import Summary from "@/pages/summary/Summary.vue";
import UserDetail from "@/pages/user/UserDetail.vue";

//设置路由
const router = new VueRouter({
    routes:[
        // {
        //     name:'web_index',
        //     path:'/web_index/:userName/:userPwd',
        //     component:Index,
        //     props($route){
        //         console.log('退出登录，进入登录页面，路由数据：', $route)
        //         return {
        //             userName: $route.params.userName,
        //             userPwd: $route.params.userPwd
        //         }
        //     }
        // },
        //设置默认路由
        {
            path:'/',
            redirect:'/summary'
        },
        {
            path:'/summary',
            component: Summary
        },
        {
            path:'/home',
            component: Home
        },
        {
            path:'/admin_list',
            component: AdminList
        },
        {
            name: 'admin_edit',
            path:'/admin_edit/:id/:adminAccount/:adminName/:adminPhone/:adminRole/:adminSex/:adminAge',
            component: AdminEdit,
            /*
            采用这种配置方式，在跳转后使用参数，直接用配置的属性名就可以了，
            无需$route.params.xxx
            */
            props($route){
                console.log('进入管理员编辑页面，路由数据：', $route)
                return {
                    id: $route.params.id, 
                    adminAccount: $route.params.adminAccount,
                    adminName:$route.params.adminName,
                    adminPhone:$route.params.adminPhone,
                    adminRole:$route.params.adminRole,
                    adminSex:$route.params.adminSex,
                    adminAge:$route.params.adminAge
                }
            }
        },
        {
            path:'/admin_save',
            component:AdminSave
        },
        {
            path:'/user_list',
            component: UserList
            // props($route){
            //     //使用params参数时 
            //    return {id: $route.params.id, name: $route.params.name} 
            // }
        },
        {
            name:'user_edit',
            path:'/user_edit/:id/:userAccount/:userName/:userPhone/:userRole/:userSex/:userAge',
            component: UserEdit,
            props($route){
                console.log('进入用户编辑页面，路由数据：', $route)
                return {
                    id: $route.params.id, 
                    userAccount: $route.params.userAccount,
                    userName:$route.params.userName,
                    userPhone:$route.params.userPhone,
                    userRole:$route.params.userRole,
                    userSex:$route.params.userSex,
                    userAge:$route.params.userAge
                }
            }
        },
        {
            path:'/user_save',
            component:UserSave
        },
        {
            path:'/ware_list',
            component: WarehouseList
        },
        {
            name:'ware_edit',
            path:'/ware_edit/:id/:warehouseName',
            component: WarehouseEdit,
            props($route){
                console.log('进入仓库编辑页面，路由数据：', $route)
                return {
                    id: $route.params.id, 
                    warehouseName: $route.params.warehouseName
                }
            }
        },
        {
            path:'/ware_save',
            component:WarehouseSave
        },
        {
            path:'/goods_list',
            component: GoodsList
        },
        {
            name:'goods_edit',
            path:'/goods_edit/:id/:goodsName/:goodsCateName/:warehouseName',
            component:GoodsEdit,
            props($route){
                console.log('进入仓库商品页面，路由数据：', $route)
                return {
                    id: $route.params.id,
                    goodsName: $route.params.goodsName,
                    goodsCateName: $route.params.goodsCateName,
                    warehouseName: $route.params.warehouseName
                }
            }
        },
        {
            path:'/goods_save',
            component:GoodsSave
        },
        {
            path:'/good_cate_list',
            component: GoodCateList
        },
        {
            name:'good_cate_edit',
            path:'/good_cate_edit/:id/:goodsCateName',
            component: GoodCateEdit,
            props($route){
                console.log('进入商品种类编辑页面，路由数据：', $route)
                return {
                    id: $route.params.id, 
                    goodsCateName: $route.params.goodsCateName
                }
            }
        },
        {
            path:'/good_cate_save',
            component: GoodCateSave
        },
        {
            name:'opt_record',
            path:'/opt_record/:opt_id/:opt_module',
            component:OptRecordList,
            props($route){
                console.log('进入操作记录页面，路由数据：', $route)
                return {
                    opt_id: $route.params.opt_id, 
                    opt_module: $route.params.opt_module
                }
            }
        },
        {
            name:'user_detail',
            path:'/user_detail/:userAccount/:userName/:userPhone/:userSole/:userSex/:userAge',
            component:UserDetail,
            props($route){
                console.log('进入用户详情页面，路由数据：', $route)
                return {
                    userAccount: $route.params.userAccount,
                    userName: $route.params.userName,
                    userPhone: $route.params.userPhone,
                    userSole: $route.params.userSole,
                    userSex: $route.params.userSex,
                    userAge: $route.params.userAge
                }
            }
        }
    ]
})

export default router

router.beforeEach((to, from, next) => {
    console.log('前置路由守卫，from：', from)
    console.log('前置路由守卫，to：', to)
    // if() {

    // }
    next();
    //只有执行了next方法才会执行页面路由跳转操作
    // if(to.meta.isAuth) {
    //     var homeStorge = window.localStorage.getItem("home")
    //     console.log('存储Home表标识：', homeStorge)
    //     if(homeStorge == 'home') {
    //         next();
    //     }
    // } else {
    //     next();
    // }

    // router.beforeEach((to, from, next) => {
    //     if (to.path === '') {
    //       next('actual-default-route'); // 重定向到实际的默认路由
    //     } else {
    //       next(); // 继续正常的导航
    //     }
    //   });
    
});